package twoD.IsoPfem.Control;

public class LoadConstraintCondition implements IConstraintCondition {

	private double s_;
	private double delta_s, delta_s_;

	public LoadConstraintCondition(double lambda0, double delta_lambda) {
		delta_s = delta_lambda;
		s_ = lambda0;
	}

	@Override
	public double f(double[] u, double[] uold, double lambda, double lambda_old) {
		return lambda - s_;
	}

	@Override
	public double[] dfdu(double[] u, double[] uold, double lambda,
			double lambda_old) {
		int n = u.length;
		return new double[n];
	}

	@Override
	public double dfdlambda(double[] u, double[] uold, double lambda,
			double lambda_old) {
		return 1;
	}

	@Override
	public void increment() {
		s_ += delta_s;
	}

	@Override
	public void setInitialLambda(double lambda0) {
		s_ = lambda0;
	}

	@Override
	public double getInitialLambda() {
		return s_;
	}

	@Override
	public double getS() {
		return s_;
	}

	@Override
	public double[] getU(double[] uGlobal) {
		return uGlobal;
	}

	@Override
	public void storeStepSize() {
		delta_s_ = delta_s;
	}

	@Override
	public void restoreStepSize() {
		delta_s = delta_s_;
	}

	@Override
	public void reduceStepSize() {
		delta_s /= 2;
		// TODO
	}
}
